<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>BrokenIRC: client_src/client.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">BrokenIRC
   &#160;<span id="projectnumber">0.0.42</span>
   </div>
   <div id="projectbrief">A &#39;not so functionnal&#39; irc server and a WIP client</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_4f864d14a2851fdffc87fa051d1e74b7.html">client_src</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">client.c File Reference</div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;stdlib.h&gt;</code><br />
<code>#include &lt;errno.h&gt;</code><br />
<code>#include &lt;string.h&gt;</code><br />
<code>#include &lt;netdb.h&gt;</code><br />
<code>#include &lt;sys/types.h&gt;</code><br />
<code>#include &lt;netinet/in.h&gt;</code><br />
<code>#include &lt;sys/socket.h&gt;</code><br />
<code>#include &lt;unistd.h&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for client.c:</div>
<div class="dyncontent">
<div class="center"><img src="client_8c__incl.png" border="0" usemap="#client__src_2client_8c" alt=""/></div>
</div>
</div>
<p><a href="client_8c_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a636f60082ffc09ccbb4a56f76d3d584d"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="client_8c.html#a636f60082ffc09ccbb4a56f76d3d584d">set_iface</a> (struct sockaddr_in *addr, int server_port, struct hostent *he, int sockfd)</td></tr>
<tr class="separator:a636f60082ffc09ccbb4a56f76d3d584d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a5796b82e83d29fbaf258b6233167a2f0"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="client_8c.html#a5796b82e83d29fbaf258b6233167a2f0">cli_loop</a> (int sockfd)</td></tr>
<tr class="separator:a5796b82e83d29fbaf258b6233167a2f0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0c99d968a34e803d378692bde2e3f18f"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="client_8c.html#a0c99d968a34e803d378692bde2e3f18f">main</a> (int ac, char **av)</td></tr>
<tr class="separator:a0c99d968a34e803d378692bde2e3f18f"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">Function Documentation</h2>
<a id="a5796b82e83d29fbaf258b6233167a2f0"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a5796b82e83d29fbaf258b6233167a2f0">&#9670;&nbsp;</a></span>cli_loop()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int cli_loop </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>sockfd</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p class="definition">Definition at line <a class="el" href="client_8c_source.html#l00035">35</a> of file <a class="el" href="client_8c_source.html">client.c</a>.</p>

<p class="reference">Referenced by <a class="el" href="client_8c_source.html#l00056">main()</a>.</p>
<div class="fragment"><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;{</div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;        <span class="keywordtype">int</span> numbytes = 0;</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;        <span class="keywordtype">char</span> buf[1024];</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;        <span class="keywordflow">while</span> (1) {</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;                <span class="keywordflow">if</span> (send(sockfd, <span class="stringliteral">&quot;Hello, world!\n&quot;</span>, 14, 0) == -1){</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;                        perror(<span class="stringliteral">&quot;send&quot;</span>);</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;                        exit (84);</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;                }</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;                printf(<span class="stringliteral">&quot;After the send function \n&quot;</span>);</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;                numbytes = recv(sockfd, buf, 1024, 0);</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;                <span class="keywordflow">if</span> (numbytes == -1) {</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;                        perror(<span class="stringliteral">&quot;recv&quot;</span>);</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;                }</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;                buf[numbytes] = <span class="charliteral">&#39;\0&#39;</span>;</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;                printf(<span class="stringliteral">&quot;Received in pid = %d, text = : %s \n&quot;</span>, getpid(), buf);</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;                sleep(1);</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;        }</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;}</div></div><!-- fragment --><div class="dynheader">
Here is the caller graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="client_8c_a5796b82e83d29fbaf258b6233167a2f0_icgraph.png" border="0" usemap="#client_8c_a5796b82e83d29fbaf258b6233167a2f0_icgraph" alt=""/></div>
<map name="client_8c_a5796b82e83d29fbaf258b6233167a2f0_icgraph" id="client_8c_a5796b82e83d29fbaf258b6233167a2f0_icgraph">
<area shape="rect" id="node2" href="client_8c.html#a0c99d968a34e803d378692bde2e3f18f" title="main" alt="" coords="120,5,171,32"/>
</map>
</div>

</div>
</div>
<a id="a0c99d968a34e803d378692bde2e3f18f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a0c99d968a34e803d378692bde2e3f18f">&#9670;&nbsp;</a></span>main()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int main </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>ac</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">char **&#160;</td>
          <td class="paramname"><em>av</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p class="definition">Definition at line <a class="el" href="client_8c_source.html#l00056">56</a> of file <a class="el" href="client_8c_source.html">client.c</a>.</p>

<p class="reference">References <a class="el" href="client_8c_source.html#l00035">cli_loop()</a>, and <a class="el" href="client_8c_source.html#l00018">set_iface()</a>.</p>
<div class="fragment"><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;{</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;        <span class="keywordtype">int</span> sockfd;</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;        <span class="keywordtype">int</span> server_port;</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;        <span class="keyword">struct </span>hostent *he;</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;        <span class="keyword">struct </span>sockaddr_in their_addr;</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;        <span class="keywordflow">if</span> (ac != 3) {</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;                fprintf(stderr, <span class="stringliteral">&quot;Usage: %s [host] [port]\n&quot;</span>, av[0]);</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;                exit(84);</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;        }</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;        he = gethostbyname(av[1]);</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;        <span class="keywordflow">if</span> (he == NULL) {</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;                exit(84);</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;        }</div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;        sockfd = socket(AF_INET, SOCK_STREAM, 0);</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;        <span class="keywordflow">if</span> (sockfd == -1) {</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;                perror(<span class="stringliteral">&quot;socket&quot;</span>);</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;                exit(84);</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;        }</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;        server_port = atoi(av[2]);</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;        <a class="code" href="client_8c.html#a636f60082ffc09ccbb4a56f76d3d584d">set_iface</a>(&amp;their_addr, server_port, he, sockfd);</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;        <a class="code" href="client_8c.html#a5796b82e83d29fbaf258b6233167a2f0">cli_loop</a>(sockfd);</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;        close(sockfd);</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;        <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;}</div><div class="ttc" id="client_8c_html_a636f60082ffc09ccbb4a56f76d3d584d"><div class="ttname"><a href="client_8c.html#a636f60082ffc09ccbb4a56f76d3d584d">set_iface</a></div><div class="ttdeci">void * set_iface(struct sockaddr_in *addr, int server_port, struct hostent *he, int sockfd)</div><div class="ttdef"><b>Definition:</b> <a href="client_8c_source.html#l00018">client.c:18</a></div></div>
<div class="ttc" id="client_8c_html_a5796b82e83d29fbaf258b6233167a2f0"><div class="ttname"><a href="client_8c.html#a5796b82e83d29fbaf258b6233167a2f0">cli_loop</a></div><div class="ttdeci">int cli_loop(int sockfd)</div><div class="ttdef"><b>Definition:</b> <a href="client_8c_source.html#l00035">client.c:35</a></div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="client_8c_a0c99d968a34e803d378692bde2e3f18f_cgraph.png" border="0" usemap="#client_8c_a0c99d968a34e803d378692bde2e3f18f_cgraph" alt=""/></div>
<map name="client_8c_a0c99d968a34e803d378692bde2e3f18f_cgraph" id="client_8c_a0c99d968a34e803d378692bde2e3f18f_cgraph">
<area shape="rect" id="node2" href="client_8c.html#a5796b82e83d29fbaf258b6233167a2f0" title="cli_loop" alt="" coords="108,5,175,32"/>
<area shape="rect" id="node3" href="client_8c.html#a636f60082ffc09ccbb4a56f76d3d584d" title="set_iface" alt="" coords="104,56,179,83"/>
</map>
</div>

</div>
</div>
<a id="a636f60082ffc09ccbb4a56f76d3d584d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a636f60082ffc09ccbb4a56f76d3d584d">&#9670;&nbsp;</a></span>set_iface()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void* set_iface </td>
          <td>(</td>
          <td class="paramtype">struct sockaddr_in *&#160;</td>
          <td class="paramname"><em>addr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>server_port</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">struct hostent *&#160;</td>
          <td class="paramname"><em>he</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>sockfd</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p class="definition">Definition at line <a class="el" href="client_8c_source.html#l00018">18</a> of file <a class="el" href="client_8c_source.html">client.c</a>.</p>

<p class="reference">Referenced by <a class="el" href="client_8c_source.html#l00056">main()</a>.</p>
<div class="fragment"><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;{</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;        addr-&gt;sin_family = AF_UNSPEC;</div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;        addr-&gt;sin_port = htons(server_port);</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;        addr-&gt;sin_addr = *((<span class="keyword">struct </span>in_addr *)he-&gt;h_addr);</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;        bzero(&amp;(addr-&gt;sin_zero), 8);</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;        <span class="keywordflow">if</span> (server_port == -1 || connect(sockfd,</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;                (<span class="keyword">struct</span> sockaddr *)&amp;addr, <span class="keyword">sizeof</span>(<span class="keyword">struct</span> sockaddr)) == -1) {</div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;                perror(<span class="stringliteral">&quot;connect&quot;</span>);</div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;                exit(1);</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;        } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;                <span class="keywordflow">return</span> addr;</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;        }</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;}</div></div><!-- fragment --><div class="dynheader">
Here is the caller graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="client_8c_a636f60082ffc09ccbb4a56f76d3d584d_icgraph.png" border="0" usemap="#client_8c_a636f60082ffc09ccbb4a56f76d3d584d_icgraph" alt=""/></div>
<map name="client_8c_a636f60082ffc09ccbb4a56f76d3d584d_icgraph" id="client_8c_a636f60082ffc09ccbb4a56f76d3d584d_icgraph">
<area shape="rect" id="node2" href="client_8c.html#a0c99d968a34e803d378692bde2e3f18f" title="main" alt="" coords="128,5,179,32"/>
</map>
</div>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
